package ai.application;

import java.util.Enumeration;
import java.util.Hashtable;

import ai.agents.astar.PathFindingAgent;
import ai.astar.DirectedGraph;
import ai.astar.Node;
import ai.gui.Gui;
import ai.json.JsonImport;

public class Controller {
	private int environmentMinX = 0;
	private int environmentMinY = 0;
	private int environmentMaxX = 12;
	private int environmentMaxY = 7;
	
	

	
	public void run(){
		Hashtable<String, Node> nodesHashtable = JsonImport.importJsonFile("network.json");
		
		PathFindingAgent pathFindingAgent = new PathFindingAgent();
		pathFindingAgent.setGraph(new DirectedGraph(nodesHashtable));
		pathFindingAgent.findPath(Config.START_NODE, Config.TARGET_NODE);
		
		Gui gui = new Gui(environmentMinX,environmentMinY, environmentMaxX, environmentMaxY);

		Environment environment = new Environment(environmentMinX,environmentMinY, environmentMaxX, environmentMaxY);
		Simulation simulation = new Simulation(gui, environment);
		
		simulation.addChangeables(pathFindingAgent);
//		gui.addDrawable(new MazeImageDrawable());
		gui.addDrawable(pathFindingAgent);

		Enumeration<String> keys = nodesHashtable.keys();
		while( keys.hasMoreElements() ) {
		  Object key = keys.nextElement();
		  Node value = nodesHashtable.get(key);
		  simulation.addDrawables(value);
		}
		
		simulation.run();
	}
	
	public static void main(String[] args){
		new Controller().run();
	}
}
